<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>
<button>发送请求1</button>
<button>发送请求2</button>
<div id="app"></div>
</body>
<script>
	const btns = document.querySelectorAll("button");
	function ajax(config={}){
		const {url,method="get",success} = config;
		const xhr = new XMLHttpRequest();
		xhr.open(method,url);
		xhr.send();
		xhr.onload = function(){
			success(xhr.response);
		};
	}
	btns[0].onclick = function(){
		ajax({
			url:"/info",
			success(res){
				console.log(res);
			}
		});
	}
	btns[1].onclick = function(){
		ajax({
			method:"post",
			url:"/sum",
			success(res) {
				alert(res);
			}
		});
	}
</script>
</html>